﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Mail;
using System.Net;
using Nascenture.Models;

namespace Nascenture.Controllers
{
    public class PageController : Controller
    {
      

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }
        public ActionResult Solutions()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }
        public ActionResult Career()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }
        public ActionResult OurTeam()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }
        public ActionResult Technologies()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }
        public ActionResult GraphicsDesigning()
        {
            return View();
        }
        public ActionResult WebDevelopment()
        {
            return View();
        }
        public ActionResult InternetMarketing()
        {
            return View();
        }
        public ActionResult QualityAssurance ()
        {
            return View();
        }
        public ActionResult SiteMap()
        {
            return View();
        }
        public ActionResult TermAndCondition()
        {
            return View();
        }

        public ActionResult PrivacyPolicy()
        {
            return View();
        }
        [ChildActionOnly]
        public ActionResult PartialRequestQuote()
        {

            return PartialView("PartialRequestQuote");
        }

        [HttpPost]
        public ActionResult PartialRequestQuote(PartialRequestQuote PartialRequestQuoteDB)
        {
            if (ModelState.IsValid)
            {
                SendEmail(PartialRequestQuoteDB.Requirement, PartialRequestQuoteDB.EmailID, PartialRequestQuoteDB.Name + " <br>" + PartialRequestQuoteDB.Phone + "<br>" + PartialRequestQuoteDB.Message);
                var message = "Hi " + PartialRequestQuoteDB.Name + @"</br></br>Thank you for your recent enquiry with Nascenture. Your enquiry has been received and is awaiting a response from our team.</br></brWe strive to answer all emails within one business day. We will attend to your query as soon as we can.</br></br>Thanks
</br>Nascenture Team";
                SendEmail("Request a Quick Quote", PartialRequestQuoteDB.EmailID, message, "");
             return  RedirectToAction("About");
            }

          return  RedirectToAction("About");
        }
        public Boolean SendEmail(string Subj, string sendEmail, string Msg)
        {

            Boolean result = false;
            string emailFrom = sendEmail;
            string emailTo = System.Configuration.ConfigurationManager.AppSettings["MailFrom"].ToString(); ;
            string SmtpServer = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"].ToString();
            string userid = System.Configuration.ConfigurationManager.AppSettings["SmtpUsername"].ToString();
            string pwd = System.Configuration.ConfigurationManager.AppSettings["SmtpPassword"].ToString();
            string portnumber = System.Configuration.ConfigurationManager.AppSettings["Portnumber"].ToString();

            System.Net.Mail.MailMessage objMail = new System.Net.Mail.MailMessage(emailTo, emailFrom);
            
            objMail.Subject = Subj;
            objMail.Body = Msg;
            objMail.Bcc.Add(sendEmail);

            SmtpClient Client = new SmtpClient(SmtpServer, int.Parse(portnumber));

            System.Net.NetworkCredential basicAuthenticationInfo = new NetworkCredential(userid, pwd);
            Client.UseDefaultCredentials = false;
            Client.Credentials = basicAuthenticationInfo;
            //Client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

            Client.Host = SmtpServer;
            objMail.IsBodyHtml = true;
            try
            {
                Client.EnableSsl = true;

                Client.Send(objMail);


                return true;
            }
            catch (Exception ex)
            {
                return false;
                //throw new InvalidCastException(ex.Message);
            }




        }
        public Boolean SendEmail(string Subj, string sendTO, string Msg,string obj)
        {

            Boolean result = false;
            string emailFrom = System.Configuration.ConfigurationManager.AppSettings["MailFrom"].ToString();;
            string emailTo = sendTO;
            string SmtpServer = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"].ToString();
            string userid = System.Configuration.ConfigurationManager.AppSettings["SmtpUsername"].ToString();
            string pwd = System.Configuration.ConfigurationManager.AppSettings["SmtpPassword"].ToString();
            string portnumber = System.Configuration.ConfigurationManager.AppSettings["Portnumber"].ToString();

            System.Net.Mail.MailMessage objMail = new System.Net.Mail.MailMessage(emailTo, emailFrom);

            objMail.Subject = Subj;
            objMail.Body = Msg;
         

            SmtpClient Client = new SmtpClient(SmtpServer, int.Parse(portnumber));

            System.Net.NetworkCredential basicAuthenticationInfo = new NetworkCredential(userid, pwd);
            Client.UseDefaultCredentials = false;
            Client.Credentials = basicAuthenticationInfo;
            //Client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

            Client.Host = SmtpServer;
            objMail.IsBodyHtml = true;
            try
            {
                Client.EnableSsl = true;

                Client.Send(objMail);


                return true;
            }
            catch (Exception ex)
            {
                return false;
                //throw new InvalidCastException(ex.Message);
            }




        }
    }
}
